<template>
  <div>
    <div class="section-header">
      <h2>专业管理</h2>
      <div class="actions">
        <el-button type="primary" @click="$emit('add')">
          <el-icon><Plus /></el-icon> 新增专业
        </el-button>
      </div>
    </div>
    
    <el-card class="table-card section-card">
      <div class="filter-container">
        <el-form :inline="true" class="filter-form">
          <el-form-item label="专业名称">
            <el-input v-model="filters.name" placeholder="请输入专业名称" clearable></el-input>
          </el-form-item>
          <el-form-item label="所属部门">
            <el-select v-model="filters.departmentId" placeholder="请选择部门" clearable>
              <el-option 
                v-for="dept in departments" 
                :key="dept.id" 
                :label="dept.name" 
                :value="dept.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="$emit('search')">搜索</el-button>
            <el-button @click="$emit('reset')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      
      <el-table
        v-loading="loading"
        :data="data"
        border
        stripe
        style="width: 100%"
      >
        <el-table-column prop="id" label="专业ID" width="100" resizable></el-table-column>
        <el-table-column prop="name" label="专业名称" min-width="120" resizable></el-table-column>
        <el-table-column prop="code" label="专业代码" min-width="120" resizable></el-table-column>
        <el-table-column prop="departmentName" label="所属部门" min-width="120" resizable></el-table-column>
        <el-table-column label="操作" fixed="right" width="200" resizable>
          <template #default="scope">
            <el-button size="small" type="primary" @click="$emit('edit', scope.row)">
              <el-icon><Edit /></el-icon> 编辑
            </el-button>
            <el-button size="small" type="danger" @click="$emit('delete', scope.row)">
              <el-icon><Delete /></el-icon> 删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <div class="pagination-container">
        <el-pagination
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          :page-size="pageSize"
          :current-page="currentPage"
          @current-change="$emit('page-change', $event)"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { Plus, Edit, Delete } from '@element-plus/icons-vue';

export default {
  name: 'MajorManagement',
  components: {
    Plus,
    Edit,
    Delete
  },
  props: {
    data: { type: Array, default: () => [] },
    departments: { type: Array, default: () => [] },
    filters: { type: Object, default: () => ({}) },
    loading: { type: Boolean, default: false },
    total: { type: Number, default: 0 },
    pageSize: { type: Number, default: 10 },
    currentPage: { type: Number, default: 1 }
  },
  emits: ['add', 'edit', 'delete', 'search', 'reset', 'page-change']
};
</script>

<style scoped>
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  margin-top: 30px;
}

.section-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  margin: 0;
}

.actions {
  margin-left: auto;
}

.section-card {
  margin-bottom: 30px;
}

.filter-container {
  margin-bottom: 20px;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>